package com.bocai.kelalacar.ui.car.main.ada;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


import com.bocai.kelalacar.R;
import com.bocai.kelalacar.bean.MyAddressBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by yuanfei on 2017/8/9.
 */

public class DetailAddressAda extends BaseAdapter {

    private Context mContext;
    private List<MyAddressBean> list;
    private int index = 0;

    public DetailAddressAda(Context mContext, List<MyAddressBean> list){
        this.mContext = mContext;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list == null?0:list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_car_num_dialog, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.text.setText(list.get(position).getFullName()+"");
        if (index == position){
            viewHolder.text.setTextColor(mContext.getResources().getColor(R.color.colorPrimary));
        }else {
            viewHolder.text.setTextColor(mContext.getResources().getColor(R.color.text_color));
        }
        return convertView;
    }
    static class ViewHolder {
        @BindView(R.id.text)
        TextView text;
        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
    public void setList(List<MyAddressBean> list){
        this.list = list;
        notifyDataSetChanged();
    }
    public void setIndex(int index){
        this.index = index;
        notifyDataSetChanged();
    }
}
